Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
jstransformer
Advanced tools
The jstransformer npm package provides a standardized interface for handling different kinds of transformations on strings, such as compiling template languages, processing markdown, or minifying code. It allows developers to use a consistent API across various transformers.
Template Compilation
Compile templates from languages like Jade/Pug to HTML.
const jstransformer = require('jstransformer');
const jade = require('jstransformer-jade');
const input = 'h1 Jade - node template engine';
const result = jstransformer(jade).render(input).body;
console.log(result);
Markdown Processing
Convert markdown syntax to HTML.
const jstransformer = require('jstransformer');
const markdown = require('jstransformer-markdown');
const input = '# Markdown Example\n\nSome *emphasis* and **strong** text.';
const result = jstransformer(markdown).render(input).body;
console.log(result);
Code Minification
Minify JavaScript code using UglifyJS.
const jstransformer = require('jstransformer');
const uglify = require('jstransformer-uglify-js');
const input = 'function add(x, y) {\n return x + y;\n}';
const result = jstransformer(uglify).render(input).body;
console.log(result);
Marked is a markdown parser and compiler. It's built for speed and is often used to convert markdown to HTML. Unlike jstransformer, which provides a unified interface for various transformations, marked focuses solely on markdown.
Pug is a high-performance template engine heavily influenced by Haml and implemented with JavaScript for Node.js and browsers. It compiles to HTML and has a powerful syntax, which is different from jstransformer's approach of providing a common API for different template engines.
UglifyJS is a JavaScript parser, minifier, compressor, or beautifier toolkit. It provides its own API for minifying JavaScript code, whereas jstransformer offers a standardized way to use UglifyJS through its interface.
Normalize the API of any jstransformer
npm install jstransformer
var transformer = require('jstransformer');
var marked = transformer(require('jstransformer-marked'));
var options = {};
var res = marked.render('Some **markdown**', options);
// => {body: 'Some <strong>markdown</strong>', dependencies: []}
This gives the same API regardless of the jstransformer passed in.
A transformer, once normalised using this module, will implement the following methods. Note that if the underlying transformer cannot be used to implement the functionality, it may ultimately just throw an error.
.render*
{body: String, dependencies: Array.<String>}
body
represents the result as a stringdependencies
is an array of files that were read in as part of the render process (or an empty array if there were no dependencies).render
transformer.render(str, options, locals);
=> {body: String, dependencies: Array.<String>}
requires the underlying transform to implement .render
or .compile
Transform a string and return an object.
.renderAsync
transformer.renderAsync(str[, options], locals, callback);
transformer.renderAsync(str[, options], locals);
=> Promise({body: String, dependencies: Array.<String>})
requires the underlying transform to implement .renderAsync
or .render
Transform a string asynchronously. If a callback is provided, it is called as callback(err, data)
, otherwise a Promise is returned.
.renderFile
transformer.renderFile(filename, options, locals)
=> {body: String, dependencies: Array.<String>}
requires the underlying transform to implement .renderFile
, .render
, .compileFile
, or .compile
Transform a file and return an object.
.renderFileAsync
transformer.renderFileAsync(filename[, options], locals, callback);
transformer.renderFileAsync(filename[, options], locals);
=> Promise({body: String, dependencies: Array.<String>})
requires the underlying transform to implement .renderFileAsync
, .renderFile
, .renderAsync
, .render
, .compileFileAsync
, .compileFile
, .compileAsync
, or .compileFile
Transform a file asynchronously. If a callback is provided, it is called as callback(err, data)
, otherwise a Promise is returned.
.inputFormats
var formats = transformer.inputFormats;
=> ['md', 'markdown']
Returns an array of strings representing potential input formats for the transform. If not provided directly by the transform, results in an array containing the name of the transform.
.outputFormat
var md = require('jstransformer')(require('jstransformer-markdown'))
var outputFormat = md.outputFormat
=> 'html'
Returns a string representing the default output format the transform would be expected to return when calling .render()
.
MIT
FAQs
Normalize the API of any jstransformer
We found that jstransformer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.